// 导入axios实例
import httpRequest from '../request/index';
// sha256加密
import sha256 from 'crypto-js/sha256';


// 获取全部年度点评列表数据
export function getAllAnnualReviewList() {
    return httpRequest({
        url: `/annualreview/all?time=${Math.round(new Date().getTime() / 1000)}`,
        method: 'get',
    });
}


// 获取年度点评列表数据
export function getAnnualReviewList(vcate, isAdmin = false) {
    if (isAdmin) {
        var header = { 'X-Admin-Req': 'Admin' }
    } else {
        var header = {}
    }
    return httpRequest({
        url: `/annualreview?vcate=${vcate}&time=${Math.round(new Date().getTime() / 1000)}`,
        method: 'get',
        headers: header,
    });
}



// 添加年度点评
export function addAnnualReview(annualReview) {
    annualReview['time'] = Math.round(new Date().getTime() / 1000);
    let params = `${annualReview.year}${annualReview.vCate}${annualReview.comment}XpFaEDYkQH`;
    annualReview['sign'] = sha256(params).toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/annualreview/add`,
        method: 'post',
        data: annualReview,
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}


// 编辑年度点评
export function editAnnualReview(id, annualReview) {
    annualReview['time'] = Math.round(new Date().getTime() / 1000);
    let params = `${annualReview.year}${annualReview.comment}XpFaEDYkQH`;
    annualReview['sign'] = sha256(params).toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/annualreview/${id}`,
        method: 'put',
        data: annualReview,
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}


// 删除年度点评
export function deleteAnnualReview(id) {
    let sign = sha256(id + 'XpFaEDYkQH').toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/annualreview/${id}?time=${Math.round(new Date().getTime() / 1000)}&sign=${sign}`,
        method: 'delete',
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}
